with v8.Class_Primitive;
with v8.Class_Value, v8.Class_String;
with v8.Class_Accessor_Info;
with v8.Generic_Handles;
limited with v8.Class_Function_Template, v8.Class_Array;
limited with v8.Class_Context;
package v8.Class_Object is
   type Object (<>) is new v8.Class_Primitive.Primitive with private;
   type Pointer is access all Object;
   -- A JavaScript object (ECMA-262, 4.3.3)

   type Object_Array is array (Positive range <>) of Pointer;

   package Handles is new v8.Generic_Handles(Pointer);

   function Set
     (this : in out Object;
      key : v8.Class_Value.Pointer; -- Handle<Value>
      value : v8.Class_Value.Pointer; -- Handle<Value>
      attribs : Property_Attribute.Enum := Property_Attribute.None
     ) return bool;

   function Set
     (this : in out Object;
      index : uint32_t;
      value : v8.Class_Value.Pointer -- Handle<Value>
     ) return bool;


   function Force_Set
     (this : in out Object;
      key : v8.Class_Value.Pointer; -- Handle<Value>
      value : v8.Class_Value.Pointer; -- Handle<Value>
      attribs : Property_Attribute.Enum := Property_Attribute.None
     ) return bool;
   -- Sets a local property on this object bypassing interceptors and
   -- overriding accessors or read-only properties.
   --
   -- Note that if the object has an interceptor the property will be set
   -- locally, but since the interceptor takes precedence the local property
   -- will only be returned if the interceptor doesn't return a value.
   --
   -- Note also that this only works for named properties.

   function Get
     (this : in out Object;
      key  : v8.Class_Value.Pointer -- Handle<Value>
     ) return v8.Class_Value.Pointer;
   -- return Local<Value>

   function Get
     (this  : in out Object;
      index : uint32_t
     ) return v8.Class_Value.Pointer;
   -- return Local<Value>


   function Get_Property_Attributes
     (this : in out Object;
      key  : v8.Class_Value.Pointer -- Handle<Value>
     ) return Property_Attribute.Enum;
   -- Gets the property attributes of a property which can be None or
   -- any combination of ReadOnly, DontEnum and DontDelete. Returns
   -- None when the property doesn't exist.


   function Has
     (this : in out Object;
      key  : v8.Class_String.Pointer -- Handle<String>
     ) return bool;
  -- TODO(1245389): Replace the type-specific versions of these
  -- functions with generic ones that accept a Handle<Value> key.

   function Delete
     (this : in out Object;
      key  : v8.Class_String.Pointer -- Handle<String>
     ) return bool;

   function Force_Delete
     (this : in out Object;
      key  : v8.Class_String.Pointer -- Handle<String>
     ) return bool;
   -- Delete a property on this object bypassing interceptors and
   -- ignoring dont-delete attributes.

   function Has
     (this  : in out Object;
      index : uint32_t
     ) return bool;


   function Delete
     (this  : in out Object;
      index : uint32_t
     ) return bool;


   function Set_Accessor
     (this : in out Object;
      name : v8.Class_String.Pointer;
      getter : v8.Class_Accessor_Info.Accessor_Getter;
      setter : v8.Class_Accessor_Info.Accessor_Setter := null;
      data : v8.Class_Value.Pointer := null;
      settings : Access_Control.Enum := Access_Control.DEFAULT;
      attribute : Property_Attribute.Enum := Property_Attribute.None
     ) return bool;


   function Get_Property_Names
     (this : in out Object
     ) return v8.Class_Array.Pointer;
   -- return Local<Array>
   -- Returns an array containing the names of the enumerable properties
   -- of this object, including properties from prototype objects.  The
   -- array returned by this method contains the same values as would
   -- be enumerated by a for-in statement over this object.

   function Get_Own_Property_Names
     (this : in out Object
     ) return v8.Class_Array.Pointer;
   -- return Local<Array>
   -- This function has the same functionality as GetPropertyNames but
   -- the returned array doesn't contain the names of properties from
   -- prototype objects.

   function Get_Prototype
     (this : in out Object
     ) return v8.Class_Value.Pointer;
   -- return Local<Value>
   -- Get the prototype object.  This does not skip objects marked to
   -- be skipped by __proto__ and it does not consult the security
   -- handler.

   function Set_Prototype
     (this      : in out Object;
      prototype : v8.Class_Value.Pointer -- Handle<Value>
     ) return bool;
   -- Set the prototype object.  This does not skip objects marked to
   -- be skipped by __proto__ and it does not consult the security
   -- handler.

   function Find_Instance_In_Prototype_Chain
     (this : in out Object;
      tmpl : access v8.Class_Function_Template.Function_Template -- Handle<FunctionTemplate>
     ) return v8.Class_Object.Pointer;
   -- return Local<Object>
   -- Finds an instance of the given function template in the prototype
   -- chain.
   -- NOTE : param tmp1 can't declare as Class_Function_Template.Pointer,
   -- else will genrate a compiler bug

   function Object_Proto_To_String (this : in out Object) return v8.Class_String.Pointer;
   -- return Local<String>
   -- Call builtin Object.prototype.toString on this object.
   -- This is different from Value::ToString() that may call
   -- user-defined toString function. This one does not.

   function Get_Constructor_Name (this : in out Object) return v8.Class_String.Pointer;
   -- Local<String>
   -- Returns the name of the function invoked as a constructor for this object.

   function Internal_Field_Count (this : in out Object) return int;
   -- Gets the number of internal fields for this Object.

   function Get_Internal_Field
     (this  : in out Object;
      index : int
     ) return v8.Class_Value.Pointer;
   -- return Local<Value>
   -- Gets the value in an internal field.

   procedure Set_Internal_Field
     (this : in out Object;
      index : int;
      value : v8.Class_Value.Pointer);
   -- Sets the value in an internal field.

   function Get_Pointer_From_Internal_Field
     (this  : in out Object;
      index : int
     ) return Address;
   -- Gets a native pointer from an internal field.

   procedure Set_Pointer_In_Internal_Field
     (this : in out Object;
      index : int;
      value : Address);
   -- Sets a native pointer in an internal field.

   -- Testers for local properties.
   function Has_Own_Property
     (this : in out Object;
      key  : v8.Class_String.Pointer
     ) return bool;
   function Has_Real_Named_Property
     (this : in out Object;
      key  : v8.Class_String.Pointer
     ) return bool;
   function Has_Real_Indexed_Property
     (this  : in out Object;
      index : Unsigned_32
     ) return bool;
   function Has_Real_Named_Callback_Property
     (this : in out Object;
      key  : v8.Class_String.Pointer
     ) return bool;

   function Get_Real_Named_Property_In_Prototype_Chain
     (this : in out Object;
      key  : v8.Class_String.Pointer  -- Handle<String>
     ) return v8.Class_Value.Pointer;
   --  return Local<Value>
   -- If result.IsEmpty() no real property was located in the prototype chain.
   -- This means interceptors in the prototype chain are not called.

   function Get_Real_Named_Property
     (this : in out Object;
      key  : v8.Class_String.Pointer -- Handle<String>
     ) return v8.Class_Value.Pointer;
   -- return Local<Value>
   -- If result.IsEmpty() no real property was located on the object or
   -- in the prototype chain.
   -- This means interceptors in the prototype chain are not called.

   function Has_Named_Lookup_Interceptor
     (this : in out Object
     ) return bool;
   -- Tests for a named lookup interceptor.

   function Has_Indexed_Lookup_Interceptor
     (this : in out Object
     ) return bool;
   -- Tests for an index lookup interceptor.

   procedure Turn_On_Access_Check (this : in out Object);
   -- Turns on access check on the object if the object is an instance of
   -- a template that has access check callbacks. If an object has no
   -- access check info, the object cannot be accessed by anyone.

   function Get_Identity_Hash (this : in out Object) return int;
   -- Returns the identity hash for this object. The current implementation
   -- uses a hidden property on the object to store the identity hash.
   --
   -- The return value will never be 0. Also, it is not guaranteed to be
   -- unique.



   -- Access hidden properties on JavaScript objects. These properties are
   -- hidden from the executing JavaScript and only accessible through the V8
   -- C++ API. Hidden properties introduced by V8 internally (for example the
   -- identity hash) are prefixed with "v8::".
   function Set_Hidden_Value
     (this : in out Object;
      key : v8.Class_String.Pointer; -- Handle<String>
      value : v8.Class_Value.Pointer -- Handle<String>
     ) return bool;
   function Get_Hidden_Value
     (this : in out Object;
      key  : v8.Class_String.Pointer -- Handle<String>
     ) return v8.Class_Value.Pointer;
   function Delete_Hidden_Value
     (this : in out Object;
      key  : v8.Class_String.Pointer -- Handle<String>
     ) return bool;

   function Is_Dirty (this : in out Object) return bool;
   -- Returns true if this is an instance of an api function (one
   -- created from a function created from a function template) and has
   -- been modified since it was created.  Note that this method is
   -- conservative and may return true for objects that haven't actually
   -- been modified.


   function Clone
     (this : in out Object
     ) return Pointer;
   -- return Local<Object>
   -- Clone this object with a fast but shallow copy.  Values will point
   -- to the same values as the original object.


   function Creation_Context
     (this : in out Object
     ) return v8.Class_Context.Pointer;
   -- return Local<Context>
   -- Returns the context in which the object was created.


   -- Set the backing store of the indexed properties to be managed by the
   -- embedding layer. Access to the indexed properties will follow the rules
   -- spelled out in CanvasPixelArray.
   -- Note: The embedding program still owns the data and needs to ensure that
   --       the backing store is preserved while V8 has a reference.
   procedure Set_Indexed_Properties_To_Pixel_Data
     (this : in out Object;
      data : access uint8_t;
      length : int);
   function Has_Indexed_Properties_In_Pixel_Data
     (this : in out Object
     ) return bool;
   function Get_Indexed_Properties_Pixel_Data
     (this : in out Object
     ) return access uint8_t;
   function Get_Indexed_Properties_Pixel_Data_Length
     (this : in out Object
     ) return int;

   -- Set the backing store of the indexed properties to be managed by the
   -- embedding layer. Access to the indexed properties will follow the rules
   -- spelled out for the CanvasArray subtypes in the WebGL specification.
   -- Note: The embedding program still owns the data and needs to ensure that
   --       the backing store is preserved while V8 has a reference.
   procedure Set_Indexed_Properties_To_External_Array_Data
     (this : in out Object;
      data : Address;
      array_type : External_Array_Type.Enum;
      number_of_elements : int);
   function Has_Indexed_Properties_In_External_Array_Data
     (this : in out Object
     ) return bool;
   function Get_Indexed_Properties_External_Array_Data
     (this : in out Object
     ) return Address;
   function Get_Indexed_Properties_External_Array_Data_Type
     (this : in out Object
     ) return External_Array_Type.Enum;
   function Get_Indexed_Properties_External_Array_Data_Length
     (this : in out Object
     ) return int;

   function Is_Callable
     (this : in out Object
     ) return bool;
   -- Checks whether a callback is set by the
   -- ObjectTemplate::SetCallAsFunctionHandler method.
   -- When an Object is callable this method returns true.

   function Call_As_Function
     (this : in out Object;
      recv : Pointer; -- Handle<Object>
      argc : int;
      argv : v8.Class_Value.Value_Array -- Handle<Value>[]
     ) return v8.Class_Value.Pointer;
   -- return Local<Value>
   -- Call an Object as a function if a callback is set by the
   -- ObjectTemplate::SetCallAsFunctionHandler method.


   function Call_As_Constructor
     (this : in out Object;
      argc : int;
      argv : v8.Class_Value.Value_Array -- Handle<Value>[]
     ) return v8.Class_Value.Pointer;
   -- return Local<Value>
   -- Call an Object as a constructor if a callback is set by the
   -- ObjectTemplate::SetCallAsFunctionHandler method.
   -- Note: This method behaves like the Function::NewInstance method.



   function Create return Pointer;
   -- Local<Object> v8::Object::New();

   function Cast is new Ada.Unchecked_Conversion (v8.Class_Value.Pointer, Pointer);
   -- Convert Value to Object

private
   type Object is new v8.Class_Primitive.Primitive with null record;

   pragma Import (CPP, Force_Set, "_ZN2v86Object8ForceSetENS_6HandleINS_5ValueEEES3_NS_17PropertyAttributeE");
   pragma Import (CPP, Internal_Field_Count, "_ZN2v86Object18InternalFieldCountEv");
   pragma Import (CPP, Get_Internal_Field, "_ZN2v86Object23CheckedGetInternalFieldEi");
   pragma Import (CPP, Set_Internal_Field, "_ZN2v86Object16SetInternalFieldEiNS_6HandleINS_5ValueEEE");
   pragma Import (CPP, Get_Pointer_From_Internal_Field, "_Z27GetPointerFromInternalFieldPN2v86ObjectEi");
   pragma Import (CPP, Set_Pointer_In_Internal_Field, "_ZN2v86Object25SetPointerInInternalFieldEiPv");
   pragma Import (CPP, Has_Own_Property, "_ZN2v86Object14HasOwnPropertyENS_6HandleINS_6StringEEE");
   pragma Import (CPP, Has_Real_Named_Property, "_ZN2v86Object20HasRealNamedPropertyENS_6HandleINS_6StringEEE");
   pragma Import (CPP, Has_Real_Indexed_Property, "_ZN2v86Object22HasRealIndexedPropertyEj");
   pragma Import (CPP, Has_Real_Named_Callback_Property, "_ZN2v86Object28HasRealNamedCallbackPropertyENS_6HandleINS_6StringEEE");
   pragma Import (CPP, Get_Real_Named_Property_In_Prototype_Chain, "_ZN2v86Object36GetRealNamedPropertyInPrototypeChainENS_6HandleINS_6StringEEE");
   pragma Import (CPP, Get_Real_Named_Property, "_ZN2v86Object20GetRealNamedPropertyENS_6HandleINS_6StringEEE");
   pragma Import (CPP, Has_Named_Lookup_Interceptor, "_ZN2v86Object25HasNamedLookupInterceptorEv");
   pragma Import (CPP, Has_Indexed_Lookup_Interceptor, "_ZN2v86Object27HasIndexedLookupInterceptorEv");
   pragma Import (CPP, Turn_On_Access_Check, "_ZN2v86Object17TurnOnAccessCheckEv");
   pragma Import (CPP, Get_Identity_Hash, "_ZN2v86Object15GetIdentityHashEv");
   pragma Import (CPP, Set_Hidden_Value, "_ZN2v86Object14SetHiddenValueENS_6HandleINS_6StringEEENS1_INS_5ValueEEE");
   pragma Import (CPP, Get_Hidden_Value, "_ZN2v86Object14GetHiddenValueENS_6HandleINS_6StringEEE");
   pragma Import (CPP, Delete_Hidden_Value, "_ZN2v86Object17DeleteHiddenValueENS_6HandleINS_6StringEEE");
   pragma Import (CPP, Is_Dirty, "_ZN2v86Object7IsDirtyEv");
   pragma Import (CPP, Clone, "_ZN2v86Object5CloneEv");
   pragma Import (CPP, Creation_Context, "_ZN2v86Object15CreationContextEv");
   pragma Import (CPP, Set_Indexed_Properties_To_Pixel_Data, "_ZN2v86Object31SetIndexedPropertiesToPixelDataEPhi");
   pragma Import (CPP, Has_Indexed_Properties_In_Pixel_Data, "_ZN2v86Object31HasIndexedPropertiesInPixelDataEv");
   pragma Import (CPP, Get_Indexed_Properties_Pixel_Data, "_ZN2v86Object29GetIndexedPropertiesPixelDataEv");
   pragma Import (CPP, Get_Indexed_Properties_Pixel_Data_Length, "_ZN2v86Object35GetIndexedPropertiesPixelDataLengthEv");
   pragma Import (CPP, Set_Indexed_Properties_To_External_Array_Data, "_ZN2v86Object39SetIndexedPropertiesToExternalArrayDataEPvNS_17ExternalArrayTypeEi");
   pragma Import (CPP, Has_Indexed_Properties_In_External_Array_Data, "_ZN2v86Object39HasIndexedPropertiesInExternalArrayDataEv");
   pragma Import (CPP, Get_Indexed_Properties_External_Array_Data, "_ZN2v86Object37GetIndexedPropertiesExternalArrayDataEv");
   pragma Import (CPP, Get_Indexed_Properties_External_Array_Data_Type, "_ZN2v86Object41GetIndexedPropertiesExternalArrayDataTypeEv");
   pragma Import (CPP, Get_Indexed_Properties_External_Array_Data_Length, "_ZN2v86Object43GetIndexedPropertiesExternalArrayDataLengthEv");
   pragma Import (CPP, Is_Callable, "_ZN2v86Object10IsCallableEv");
   pragma Import (CPP, Call_As_Function, "_ZN2v86Object14CallAsFunctionENS_6HandleIS0_EEiPNS1_INS_5ValueEEE");
   pragma Import (CPP, Call_As_Constructor, "_ZN2v86Object17CallAsConstructorEiPNS_6HandleINS_5ValueEEE");
   pragma Import (CPP, Create, "_ZN2v86Object3NewEv");
   pragma Import (CPP, Get_Property_Attributes, "_ZN2v86Object21GetPropertyAttributesENS_6HandleINS_5ValueEEE");
   pragma Import (CPP, Set_Accessor, "_ZN2v86Object11SetAccessorENS_6HandleINS_6StringEEEPFNS1_INS_5ValueEEENS_5LocalIS2_EERKNS_12AccessorInfoEEPFvS7_NS6_IS4_EESA_ES5_NS_13AccessControlENS_17PropertyAttributeE");
   pragma Import (CPP, Get_Property_Names, "_ZN2v86Object16GetPropertyNamesEv");
   pragma Import (CPP, Get_Own_Property_Names, "_ZN2v86Object19GetOwnPropertyNamesEv");
   pragma Import (CPP, Get_Prototype, "_ZN2v86Object12GetPrototypeEv");
   pragma Import (CPP, Set_Prototype, "_ZN2v86Object12SetPrototypeENS_6HandleINS_5ValueEEE");
   pragma Import (CPP, Find_Instance_In_Prototype_Chain, "_ZN2v86Object28FindInstanceInPrototypeChainENS_6HandleINS_16FunctionTemplateEEE");
   pragma Import (CPP, Object_Proto_To_String, "_ZN2v86Object19ObjectProtoToStringEv");
   pragma Import (CPP, Get_Constructor_Name, "_ZN2v86Object18GetConstructorNameEv");


end v8.Class_Object;
